package com.lirh.data.mongodbdemo.service.impl;

import com.lirh.data.mongodbdemo.dao.CommentDao;
import com.lirh.data.mongodbdemo.model.Comment;
import com.lirh.data.mongodbdemo.service.CommentService;
import com.lirh.data.mongodbdemo.util.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("commentService")
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Autowired
    private SnowFlakeUtil snowFlakeUtil;
    @Override
    public List<Comment> findAll() {
        return commentDao.findAll();
    }

    @Override
    public void save(Comment comment, String sid) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        comment.setPublishtime(simpleDateFormat.format(date));
        comment.set_id(snowFlakeUtil.nextId()+"");
        comment.setThunbup(0);
        System.out.println(sid);
        comment.setSid(sid);
        commentDao.save(comment);
    }
}
